package com.yootk.main;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.*;

/**
 * Environment，配置环境管理
 */
public class Demo04_Environment {
    private static final Logger LOGGER = LoggerFactory.getLogger(Demo04_Environment.class);

    public static void main(String[] args) {
//        test1();
        test2();
    }

    /**
     * 获取操作系统与JVM变量信息
     */
    public static void test1() {
        ConfigurableEnvironment environment = new StandardEnvironment();
        MutablePropertySources sources = environment.getPropertySources();  // 系统的环境变量
        for (PropertySource source : sources) {
            LOGGER.info("{}：{}", source.getName(), source.getSource());
        }
    }

    /**
     * 获取属性的内容
     * Add VM Options：
     * -Dyootk=沐言科技：www.yootk.com -Dedu=李兴华高薪就业编程训练营：edu.yootk.com
     */
    public static void test2() {
        PropertyResolver resolver = new StandardEnvironment();
        LOGGER.info("【获取静态设置的JVM属性】JDK版本 = {}", resolver.getProperty("java.specification.version"));
        LOGGER.info("【获取动态设置的JVM属性】yootk = {}", resolver.getProperty("yootk"));
        LOGGER.info("【获取动态设置的JVM属性】edu = {}", resolver.getProperty("edu"));
    }
}
